<?php
namespace app\index\event;

class Sql
{
    /**
    * 安装时触发
    * @return bool 只有返回true时才会往下执行
    */
	public function install()
    {
        //批量写入插件配置
        $result = \daicuo\Op::write([
            'site_title'       => '呆错后台开发框架',
            'site_keywords'    => '欢迎使用呆错（DaiCuo）开发您的WEB项目',
            'site_description' => '呆错是一款基于ThinkPHP、Bootstrap、Jquery的极速后台开发框架',
            'theme'            => 'default_pc',
            'theme_wap'        => 'default_wap',
        ],'index','system','config','0','yes');
        
        
        //批量添加路由伪静态
        $result = \daicuo\Route::save_all([
            [
                'rule'        => '/demo',
                'address'     => 'index/index/demo',
                'method'      => 'get',
                'op_module'   => 'index',
                'op_controll' => 'system',
                'op_action'   => 'route',
            ],
            [
                'rule'        => '/test',
                'address'     => 'index/index/test',
                'method'      => 'get',
                'op_module'   => 'index',
                'op_controll' => 'system',
                'op_action'   => 'route',
            ],
        ]);
        
        //批量添加分类
        $result = \daicuo\Term::save_all([
            [
                'term_name'       => '分类1',
                'term_slug'       => 'category1',
                'term_module'     => 'index',
                'term_status'     => 'normal',
                'term_order'      => 1,
                'term_type'       => 'category',
                'term_info'       => '分类1的说明',
                'term_tpl'        => 'index',
                'term_navbar'     => 'no',
            ],
            [
                'term_name'       => '分类2',
                'term_slug'       => 'category2',
                'term_module'     => 'index',
                'term_status'     => 'normal',
                'term_order'      => 2,
                'term_type'       => 'category',
                'term_info'       => '分类2的说明',
                'term_tpl'        => 'index',
                'term_navbar'     => 'no',
            ],
        ]);
        
        //返回结果
        return true;
	}
    
    /**
    * 升级时触发
    * @return bool 只有返回true时才会往下执行
    */
    public function upgrade()
    {
        return true;
    }
    
    /**
    * 卸载时触发
    * @return bool 只有返回true时才会往下执行
    */
    public function remove()
    {
        return $this->unInstall();
    }
    
    /**
    * 删除时触发
    * @return bool 只有返回true时才会往下执行
    */
    public function unInstall()
    {
        //删除插件配置
        \daicuo\Op::delete_module('index');
        //删除插件分类
        \daicuo\Term::delete_module('index');
        //删除插件用户
        \daicuo\User::delete_module('index');
        //直接返回结果
        return true;
	}
	
}